<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/tag.jsp"%>
<link href="/resourses/css/bootstrap-slider.min.css" rel="stylesheet">
<h3>
    <span class="glyphicon glyphicon-tasks" style="color: rgb(102, 101, 126);">
    所属项目名：${mission.project.name}
        </span>
</h3>
<h4>
    <span class="glyphicon glyphicon-star" style="color: rgb(255, 218, 119);">分值：${mission.score}</span>
</h4>
<h3>
    <span class="glyphicon glyphicon-wrench" style="color: rgb(102, 101, 126);font-size: 16px"> 任务状态: </span>
    <c:if test="${mission.state == 2}">
        <span class="glyphicon glyphicon-ok" style="color: rgb(59, 141, 73);font-size: 16px"> 通过</span>
    </c:if>
    <c:if test="${mission.state == 1}">
        <span class="glyphicon glyphicon-time" style="color: rgb(39, 115, 150);font-size: 16px"> 待检查</span>
    </c:if>
    <c:if test="${mission.state == 0}">
        <span class="glyphicon glyphicon-fire" style="color: rgb(255, 115, 0);font-size: 16px"> 未接任务</span>
    </c:if>

    <c:if test="${mission.state == -1}">
        <span class="glyphicon glyphicon-refresh" style="color: rgb(39, 115, 150);font-size: 16px"> 处理中</span>
    </c:if>
    <c:if test="${mission.state == -2}">
        <span class="glyphicon glyphicon-remove" style="color: rgb(255, 0, 0);font-size: 16px"> 未通过</span>
    </c:if>
</h3>
<h4>
    <span class="glyphicon glyphicon-cloud-upload" style="color: rgb(102, 101, 126);"> svn地址：${mission.project.svnUrl}</span>

</h4>
<h4>
    <span class="glyphicon glyphicon-user" style="color: rgb(102, 101, 126);"> 发布者：${mission.originator.realName}</span>

</h4>
<h4>
    <span class="glyphicon glyphicon-calendar" style="color: rgb(102, 101, 126);">
    发布时间：<fmt:formatDate value="${mission.generateDate}" pattern="yyyy年MM月dd日hh点mm分"/>
    </span></h4>
<p style="width: 250px">
    <h4>任务描述：</h4>
    ${mission.detail}
<br/>
    <c:if test="${mission.added !=null}">
    <a href="${mission.added}" class="btn">附件</a>
    </c:if>
</p>

<c:if test="${mission.state < 0}">
    <div id="submit_input" class="hidden">
        <form role="form"  id="note_info">
            <div class="form-group">
                <label for="complete_slider">完成度：</label>
                <input class="form-control" type="text" id="complete_slider" name="complete"
                       data-provide="slider"
                       data-slider-min="1"
                       data-slider-max="100"/>
            </div>
            <div class="form-group">
                <label for="svn_rev">SVN版本号：</label>
                <input type="text" name="svnRev" id="svn_rev">
            </div>
            <div class="form-group">
                <label for="note_detail">描述：</label>
                <textarea rows="3" cols="30" form="note_info" id="note_detail" name="detail"></textarea>
            </div>
            <input type="hidden" name="missionId" value="${mission.id}">
            <div class="btn-group">
                <button type="button" onclick="doSubmit()">提交</button>
                <button type="button" onclick="cancelSubmit()">取消</button>
            </div>
        </form>
        <br/>
    </div>
    <div class="btn-group" id="submit_btn">
        <a class="btn" onclick="missionSubmit(${mission.id})"> 完成任务</a>
    </div>
</c:if>

<c:if test="${mission.state == 0}">
    <div class="btn-group">
        <a class="btn" onclick="missionAccept(${mission.id})"> 接收任务</a>
    </div>
</c:if>

<script src="/resourses/js/bootstrap-slider.min.js"></script>
<script type="application/javascript">
//任务提交表单显示开关
    function missionSubmit(missionId){
        $("#submit_input").removeClass("hidden");
        $("#submit_btn").addClass("hidden");
    }
    function cancelSubmit(){
        $("#submit_btn").removeClass("hidden");
        $("#submit_input").addClass("hidden");
    }
//任务note表单提交
    function doSubmit(){
        //检查svn版本为数字
        if(confirm("确认提交")){
            $.ajax({
                type:"POST",
                url:"/t/n/noteSubmit",
                data:$("#note_info").serialize(),
                dataType:"json",
                success: function (result) {
                    //提交成功-刷新c栏
                    if(result['success']){
                        var data = result['data'];
                        $("#missionNum").html(data.unhandledNum);
                        //刷新B栏
                        home.a.init({
                            "menuId":"h-menu-task"
                        });
                        //刷新C栏
                        home.b.getMissionById(data.missionId);

                    }else{
                        alert(result['error']);
                    }
                }
            });
        }
    }
    function missionAccept(missionId){
        $.ajax({
            type:"GET",
            url:"/t/m/"+missionId+"/acceptMission",
            data:{},
            dataType:"json",
            success:function(result){
                var data = result['data'];
                //刷新B栏
                home.a.init({
                    "menuId":"h-menu-task"
                });
                //刷新C栏
                home.b.getMissionById(data.missionId);
            }
        });
    }
</script>
